/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.core.services.assembler;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import com.teknei.acabus.core.entities.TableA;
import com.teknei.acabus.core.entities.TableB;
import com.teknei.acabus.core.entities.TableC;
import com.teknei.acabus.dto.TableCDTO;

/**
 * Session Bean implementation class TableCAssembler
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 */
@Stateless
@LocalBean
public class TableCAssembler extends Assembler<TableCDTO, TableC>{

    /**
     * Default constructor. 
     */
    public TableCAssembler() {
        super();
    }

    /* (non-Javadoc)
     * @see com.teknei.acabus.core.services.assembler.Assembler#getDTOTransform(java.lang.Object)
     */
    @Override
	public TableCDTO getDTOTransform(TableC mapping) {
		TableCDTO dto = new TableCDTO();
		if(mapping == null){
			return null;
		}
		dto.setIdField(mapping.getIdField());
		dto.setValue(mapping.getValue());
		dto.setValueTableA(mapping.getTableA().getValue());
		dto.setValueTableB(mapping.getTableB().getValue());
		dto.setIdTableA(mapping.getTableA().getIdField());
		dto.setIdTableB(mapping.getTableB().getIdField());
		dto.setDescription(mapping.getDescription());
		return dto;
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.core.services.assembler.Assembler#getMappingTransform(java.lang.Object)
	 */
	@Override
	public TableC getMappingTransform(TableCDTO dto) {
		TableC tableC = new TableC();
		tableC.setDescription(dto.getDescription());
		tableC.setValue(dto.getValue());
		if(dto.getIdField() != 0){
			tableC.setIdField(dto.getIdField());
		}
		if(dto.getIdTableA() != 0){
			TableA a = new TableA();
			a.setIdField(dto.getIdTableA());
			tableC.setTableA(a);
		}
		if(dto.getIdTableB() != 0){
			TableB b = new TableB();
			b.setIdField(dto.getIdTableB());
			tableC.setTableB(b);
		}
		return tableC;
	}

}
